<!DOCTYPE html>
<html>
<head>
<title>编辑栏目</title>
#include("../include/common.html")
</head>
<body class="gray-bg">
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="ibox float-e-margins">
            <div class="ibox-title">
                <h5>编辑栏目</h5>
            </div>
           <form id="inputForm" action="update" method="post">
                <input type="hidden" name="id" value="#(category.id)">
                <div class="ibox-content">
                    <div class="form-horizontal clearfix">
                        <div class="form-group">
                            <label class="col-sm-3 control-label">名称：</label>
                            <div class="col-sm-3">
                                <input class="form-control" type="text" name="name" value="#(category.name)">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">上级分类：</label>
                            <div class="col-sm-3">
                                <select class="form-control" name="parentId">
                                    <option value="">顶级分类</option>
                                    #for(categoryItem : categoryTree)
                                        <option value="#(categoryItem.id)" #if(category.parentId==categoryItem.id) selected #end>
                                            #if(categoryItem.grade != 0)
                                                 #for(i = 0; i < categoryItem.grade; i++)
                                                    &nbsp;&nbsp;
                                                #end
                                            #end
                                            #(categoryItem.name)
                                        </option>
                                    #end
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">是否做为菜单：</label>
                            <div class="col-sm-3">
                                <div class="radio">
                                    <label class="m-r"><input name="isMenu" value="true" type="radio" #if(category.isMenu) checked #end>是</label>
                                    <label class="m-r"><input name="isMenu" value="false" type="radio" #if(!category.isMenu) checked #end>否</label>
                                </div>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">类型：</label>
                            <div class="col-sm-3">
                                <div class="radio" id="type">
                                    <label class="m-r"><input name="type" value="1" type="radio" #if(category.type==1) checked #end>列表栏目</label>
                                    <label class="m-r"><input name="type" value="2" type="radio" #if(category.type==2) checked #end>单页面</label>
                                    <label class="m-r"><input name="type" value="3" type="radio" #if(category.type==3) checked #end>链接</label>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="form-horizontal clearfix" id="type1" #if(category.type==1) #else style="display: none;" #end>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">模型：</label>
                            <div class="col-sm-3">
                                <select class="form-control" name="modelId" id="modelId">
                                    <option value="">--请选择--</option>
                                    #for(model : models)
                                        <option value="#(model.id)" #if(category.modelId==model.id) selected #end>#(model.name)</option>
                                    #end
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">列表模板：</label>
                            <div class="col-sm-3">
                                <input class="form-control" type="text" name="listTemplate" id="listTemplate" value="#(category.listTemplate)">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">内容模板：</label>
                            <div class="col-sm-3">
                                <input class="form-control" type="text" name="contentTemplate" id="contentTemplate" value="#(category.contentTemplate)">
                            </div>
                        </div>
                    </div>
                    <div class="form-horizontal clearfix" id="type2" #if(category.type==2) #else style="display: none;" #end>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">页面模板：</label>
                            <div class="col-sm-3">
                                <input class="form-control" type="text" name="pageTemplate" value="#(category.pageTemplate)">
                            </div>
                        </div>
                    </div>
                    <div class="form-horizontal clearfix" id="type3" #if(category.type==3) #else style="display: none;" #end>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">链接地址：</label>
                            <div class="col-sm-3">
                                <input class="form-control" type="text" name="url" value="#(category.url)">
                            </div>
                        </div>
                    </div>
                    <div class="form-horizontal clearfix" id="baseInfo" #if(category.type==3) style="display: none;" #end>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">图片：</label>
                            <div class="col-sm-3">
                                <input type="text" name="image" class="form-control" value="#(category.image)"/>
                            </div>
                            <div class="col-sm-3">
                                <a href="javascript:;" id="filePicker" class="btn btn-primary">选择文件</a>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">标题：</label>
                            <div class="col-sm-3">
                                <input class="form-control" type="text" name="title" value="#(category.title)">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">关键词：</label>
                            <div class="col-sm-3">
                                <input class="form-control" type="text" name="keywords" value="#(category.keywords)">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">描述：</label>
                            <div class="col-sm-3">
                                <input class="form-control" type="text" name="description" value="#(category.description)">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">简介：</label>
                            <div class="col-sm-8">
                               <textarea id="introduction" name="introduction" class="ibox-content no-padding" style="height: 250px;"></textarea>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="modal-footer col-sm-3 col-sm-offset-2">
                    <button type="submit" class="btn btn-w-m btn-primary">确定</button>
                    <button type="button" class="btn btn-w-m btn-default" onclick="history.back(); return false;">取消</button>
                </div>
            </form>
        </div>
    </div>
</body>
</html>
<script type="text/javascript">
function loadTemplate(){
    var modelId = $("#modelId").val();
    if(!modelId){
        return;
    }
    $.ajax({
        url: "modelTemplate",
        type: "POST",
        data: {"modelId":modelId},
        dataType: "json",
        cache: false,
        success: function(data) {
            $("#listTemplate").val(data.listTemplate);
            $("#contentTemplate").val(data.contentTemplate);
        }
    });
}

loadTemplate();

$().ready(function() {

    var $inputForm = $("#inputForm");
    var $type = $("#type");
    var $modelId = $("#modelId");
    var $introduction = $("#introduction");
    var $filePicker = $("#filePicker");
    
    $filePicker.uploader();
    
    $introduction.editor();
    
    $type.on("click","input[type='radio']",function(){
    	$("#type1").hide();
        $("#type2").hide();
        $("#type3").hide();
        $("#baseInfo").hide();
        if("1"==$(this).val()){
            $modelId.rules("add",{required:true});
            $("#baseInfo").show();
        }else if("2"==$(this).val()){
            $modelId.rules("remove");
            $("#baseInfo").show();
        }else if("3"==$(this).val()){
            $modelId.rules("remove");
            $("#baseInfo").hide();
        }
        $("#type"+$(this).val()).show();
    });
    
   $modelId.change(function() {
       loadTemplate();
    });
    
    
    // 表单验证
    $inputForm.validate({
        rules: {
            name: "required",
            type: "required"
        }
    });

});
</script>
